/****************************************************
文件：TestAssetBundleManager.cs
作者：UnitySir
邮箱：zouajck@foxmail.com
日期：2021/03/22 20:24:37
功能：Nothing
*****************************************************/

using UnityEngine;

namespace DSFramework
{
    public class TestAssetBundleManager : MonoBehaviour
    {
        // 场景名称
        private string _SceneName = "scene_1";

        // AB 包名称
        private string _AssetBundleName = "scene_1/prefabs.ab";

        // 资源名称
        private string _AssetName = "Tip.prefab";


        private void Start()
        {
            Debug.Log("开始 Asset Bundle 框架测试");

            // 调用 AB 包（连锁只能调用依赖资源）
            StartCoroutine(AssetBundleManager.GetInstance().LoadAssetBundlePack(_SceneName, _AssetBundleName, LoadAllABComplete));
        }

        /// <summary>
        /// 所有AB 包加载完毕的事件回调
        /// </summary>
        /// <param name="abName"></param>
        private void LoadAllABComplete(string abName)
        {
            Debug.Log("所有 Asset Bundle 资源加载完毕");
            // 提取资源
            Object tmpObj = AssetBundleManager.GetInstance().LoadAsset(_SceneName, _AssetBundleName, _AssetName, false);

            if (tmpObj != null)
            {
                Instantiate(tmpObj);
            }
        }


        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                // 释放当前场景的所有资源
                Debug.Log("释放场景 " + _SceneName + " 的所有资源");
                AssetBundleManager.GetInstance().DisposeAllAsset(_SceneName);
            }
        }
    }
}